package com.bh.controller;

import com.bh.domain.CommonResult;
import com.bh.domain.ResultCode;
import com.bh.domain.Role;
import com.bh.service.RoleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author13007
 * @date2022/10/25
 * @apiNote
 */
@Component
@RestController
@RequestMapping("/sys/role")
public class RoleController  {
    @Autowired
    private RoleService RoleService;

    /**
     * 查询角色列表  分页
     */
    @GetMapping("/list")
    public CommonResult list(Role role) {
        List<Role> list = RoleService.selectRoleList(role);
        return  new CommonResult(ResultCode.SUCCESS,"查询成功",RoleService.selectRoleList(role));
    }

    /**
     * 获取角色详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult<?> getInfo(@PathVariable("id") Long id) {
        RoleService.selectRoleById(id);
        return  new CommonResult (ResultCode.SUCCESS,"查询成功",RoleService.selectRoleById(id));
    }

    /**
     * 新增角色
     */
    @PostMapping("/add")
    public CommonResult<?> add(@RequestBody Role role) {
        RoleService.insertRole(role);
        return  new CommonResult (ResultCode.SUCCESS,"新增成功");
    }

    /**
     * 修改角色
     */
    @PutMapping("edit")
    public CommonResult<?> edit(@RequestBody Role role) {
        RoleService.updateRole(role);
       return new CommonResult (ResultCode.SUCCESS,"修改成功");
    }

    /**
     * 删除角色
     */
    @DeleteMapping("/{id}")
    public CommonResult<?> remove(@PathVariable Long id) {
        RoleService.deleteRoleById(id);
        return new CommonResult (ResultCode.SUCCESS,"删除成功");
    }
}
